package com.ruoyi.web.controller.systembasic;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesSupplier;
import com.ruoyi.mes.systembasic.service.ISmesSupplierService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商管理Controller
 *
 * @author simpsense
 * @date 2020-11-26
 */
@RestController
@RequestMapping("/systembasic/supplier")
public class SmesSupplierController extends BaseController
{
    @Autowired
    private ISmesSupplierService smesSupplierService;

    /**
     * 查询供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesSupplier smesSupplier)
    {
        startPage();
        List<SmesSupplier> list = smesSupplierService.selectSmesSupplierList(smesSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:export')")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesSupplier smesSupplier)
    {
        List<SmesSupplier> list = smesSupplierService.selectSmesSupplierList(smesSupplier);
        ExcelUtil<SmesSupplier> util = new ExcelUtil<SmesSupplier>(SmesSupplier.class);
        return util.exportExcel(list, "supplier");
    }

    /**
     * 获取供应商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:query')")
    @GetMapping(value = "/{supplierNo}")
    public AjaxResult getInfo(@PathVariable("supplierNo") String supplierNo)
    {
        return AjaxResult.success(smesSupplierService.selectSmesSupplierById(supplierNo));
    }

    /**
     * 新增供应商管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesSupplier smesSupplier)
    {
        return toAjax(smesSupplierService.insertSmesSupplier(smesSupplier));
    }

    /**
     * 修改供应商管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:edit')")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesSupplier smesSupplier)
    {
        return toAjax(smesSupplierService.updateSmesSupplier(smesSupplier));
    }

    /**
     * 删除供应商管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierNos}")
    public AjaxResult remove(@PathVariable String[] supplierNos)
    {
        return toAjax(smesSupplierService.deleteSmesSupplierByIds(supplierNos));
    }
}